
package View;

import Control.ctrCliente;
import java.awt.GraphicsEnvironment;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

public class limCliente extends javax.swing.JFrame {

    private final ctrCliente control;
    private MaskFormatter maskCPF, maskCEP, maskCEL, maskRES, maskCOM;

    public limCliente(ctrCliente control) {
        this.control = control;
        initComponents();
        field_codigo.setText("");
        card_cliente.addTab("Animais", control.chamaViewAnimal());
        //Centraliza janela
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        int x = ge.getCenterPoint().x - (this.getWidth()/2);
        int y = ge.getCenterPoint().y - (this.getHeight()/2);
        setLocation(x, y);
        //Setar foco na interface superior
        JDialog dia = new JDialog();
        dia.setModal(true);
        dia.setContentPane(getContentPane());
        dia.setBounds(this.getBounds());
        dia.setVisible(true);
        dia.setResizable(false);
    }

    private void setAtributos(ArrayList<String> result) {
        field_codigo.setText("");
        field_codigo.setText(result.get(0));
        field_nome.setText(result.get(1));
        field_cpf.setText(result.get(2));
        field_email.setText(result.get(3));
        field_tel_celular.setText(result.get(4));
        field_tel_residencial.setText(result.get(5));
        field_tel_comercial.setText(result.get(6));
        field_end_rua.setText(result.get(7));
        field_end_bairro.setText(result.get(8));
        field_end_cep.setText(result.get(9));
        field_end_cidade.setText(result.get(10));
    }

    private void limpaFields(){
        field_pesquisa.setText("");
        field_codigo.setText("");
        field_nome.requestFocus();
        field_nome.setText("");
        field_cpf.setText("");
        field_email.setText("");
        field_tel_celular.setText("");
        field_tel_comercial.setText("");
        field_tel_residencial.setText("");
        field_end_rua.setText("");
        field_end_bairro.setText("");
        field_end_cep.setText("");
        field_end_cidade.setText("");
    }
   
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label_titulo = new javax.swing.JLabel();
        card_cliente = new javax.swing.JTabbedPane();
        panel_cliente = new javax.swing.JPanel();
        panel_pesquisar = new javax.swing.JPanel();
        field_pesquisa = new javax.swing.JTextField();
        label_pesquisar = new javax.swing.JLabel();
        panel_dados = new javax.swing.JPanel();
        label_nome = new javax.swing.JLabel();
        field_nome = new javax.swing.JTextField();
        label_cpf = new javax.swing.JLabel();
        label_email = new javax.swing.JLabel();
        field_email = new javax.swing.JTextField();
        try {
            maskCPF = new MaskFormatter("###.###.###-##");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_cpf do cliente.");
        }
        field_cpf = new JFormattedTextField(maskCPF);
        panel_endereco = new javax.swing.JPanel();
        label_end_bairro = new javax.swing.JLabel();
        field_end_bairro = new javax.swing.JTextField();
        field_end_rua = new javax.swing.JTextField();
        label_end_rua = new javax.swing.JLabel();
        label_end_cep = new javax.swing.JLabel();
        label_end_cidade = new javax.swing.JLabel();
        field_end_cidade = new javax.swing.JTextField();
        try {
            maskCEP = new MaskFormatter("##.###-###");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_cep do cliente.");
        }
        field_end_cep = new JFormattedTextField(maskCEP);
        panel_telefone = new javax.swing.JPanel();
        label_tel_celular = new javax.swing.JLabel();
        label_tel_residencial = new javax.swing.JLabel();
        label_tel_comercial = new javax.swing.JLabel();
        try {
            maskCEL = new MaskFormatter("(##) ####-####");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_tel_celular do cliente.");
        }
        field_tel_celular = new JFormattedTextField(maskCEL);
        try {
            maskRES = new MaskFormatter("(##) ####-####");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_tel_residencial do cliente.");
        }
        field_tel_residencial = new JFormattedTextField(maskRES);
        try {
            maskCOM = new MaskFormatter("(##) ####-####");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_tel_comercial do cliente.");
        }
        field_tel_comercial = new JFormattedTextField(maskCOM);
        panel_botoes_caminhamento = new javax.swing.JPanel();
        botao_primeiro = new javax.swing.JButton();
        botao_anterior = new javax.swing.JButton();
        field_codigo = new java.awt.TextField();
        botao_proximo = new javax.swing.JButton();
        botao_ultimo = new javax.swing.JButton();
        panel_botoes_crud = new javax.swing.JPanel();
        botao_alterar = new javax.swing.JButton();
        botao_gravar = new javax.swing.JButton();
        botao_novo = new javax.swing.JButton();
        botao_excluir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Clientes");
        setName("frame_cliente"); // NOI18N

        label_titulo.setFont(label_titulo.getFont().deriveFont(label_titulo.getFont().getStyle() | java.awt.Font.BOLD, 25));
        label_titulo.setForeground(new java.awt.Color(255, 0, 0));
        label_titulo.setText("Cadastro de Clientes & Animais");

        card_cliente.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        card_cliente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        card_cliente.setMaximumSize(new java.awt.Dimension(849, 380));
        card_cliente.setPreferredSize(new java.awt.Dimension(848, 333));

        panel_cliente.setMaximumSize(new java.awt.Dimension(849, 303));
        panel_cliente.setPreferredSize(new java.awt.Dimension(849, 303));

        panel_pesquisar.setBackground(new java.awt.Color(153, 255, 153));

        field_pesquisa.setToolTipText("Digite aqui as iniciais do cliente.");
        field_pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                field_pesquisaActionPerformed(evt);
            }
        });

        label_pesquisar.setFont(new java.awt.Font("Tahoma", 1, 14));
        label_pesquisar.setText("PESQUISAR:");

        javax.swing.GroupLayout panel_pesquisarLayout = new javax.swing.GroupLayout(panel_pesquisar);
        panel_pesquisar.setLayout(panel_pesquisarLayout);
        panel_pesquisarLayout.setHorizontalGroup(
            panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_pesquisarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label_pesquisar)
                .addGap(18, 18, 18)
                .addComponent(field_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        panel_pesquisarLayout.setVerticalGroup(
            panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_pesquisarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_pesquisar)
                    .addComponent(field_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panel_dados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        label_nome.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_nome.setText("Nome:");

        label_cpf.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_cpf.setText("CPF:");

        label_email.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_email.setText("E-mail:");

        javax.swing.GroupLayout panel_dadosLayout = new javax.swing.GroupLayout(panel_dados);
        panel_dados.setLayout(panel_dadosLayout);
        panel_dadosLayout.setHorizontalGroup(
            panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_dadosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label_nome)
                    .addGroup(panel_dadosLayout.createSequentialGroup()
                        .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label_email)
                            .addComponent(label_cpf))
                        .addGap(18, 18, 18)
                        .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(field_cpf, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(field_email, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(field_nome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))))
                .addGap(22, 22, 22))
        );
        panel_dadosLayout.setVerticalGroup(
            panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_dadosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_nome)
                    .addComponent(field_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(field_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(panel_dadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_email)
                    .addComponent(field_email, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panel_endereco.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        label_end_bairro.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_bairro.setText("Bairro:");

        label_end_rua.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_rua.setText("Rua:");

        label_end_cep.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_cep.setText("CEP:");

        label_end_cidade.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_cidade.setText("Cidade:");

        javax.swing.GroupLayout panel_enderecoLayout = new javax.swing.GroupLayout(panel_endereco);
        panel_endereco.setLayout(panel_enderecoLayout);
        panel_enderecoLayout.setHorizontalGroup(
            panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_enderecoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label_end_bairro)
                    .addComponent(label_end_rua)
                    .addComponent(label_end_cidade)
                    .addComponent(label_end_cep))
                .addGap(27, 27, 27)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(field_end_cidade, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                    .addComponent(field_end_cep, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                    .addComponent(field_end_bairro, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                    .addComponent(field_end_rua, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                .addContainerGap())
        );
        panel_enderecoLayout.setVerticalGroup(
            panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_enderecoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_end_rua)
                    .addComponent(field_end_rua))
                .addGap(9, 9, 9)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_end_bairro)
                    .addComponent(field_end_bairro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_end_cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_end_cep))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label_end_cidade)
                    .addComponent(field_end_cidade))
                .addContainerGap())
        );

        panel_telefone.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Telefone", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        label_tel_celular.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_tel_celular.setText("TEL. CEL.:");

        label_tel_residencial.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_tel_residencial.setText("TEL. RES.:");

        label_tel_comercial.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_tel_comercial.setText("TEL. COM.:");

        javax.swing.GroupLayout panel_telefoneLayout = new javax.swing.GroupLayout(panel_telefone);
        panel_telefone.setLayout(panel_telefoneLayout);
        panel_telefoneLayout.setHorizontalGroup(
            panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_telefoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label_tel_celular)
                    .addComponent(label_tel_residencial)
                    .addComponent(label_tel_comercial))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(field_tel_celular, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                    .addComponent(field_tel_residencial, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                    .addComponent(field_tel_comercial, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))
                .addContainerGap())
        );
        panel_telefoneLayout.setVerticalGroup(
            panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_telefoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_tel_celular)
                    .addComponent(field_tel_celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_tel_residencial)
                    .addComponent(field_tel_residencial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_tel_comercial)
                    .addComponent(field_tel_comercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14))
        );

        botao_primeiro.setFont(new java.awt.Font("Tahoma", 1, 11));
        botao_primeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/primeiro_registro.gif"))); // NOI18N
        botao_primeiro.setToolTipText("Ir para o primeiro cliente");
        botao_primeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_primeiroActionPerformed(evt);
            }
        });

        botao_anterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/registro_anterior.gif"))); // NOI18N
        botao_anterior.setToolTipText("Cliente anterior");
        botao_anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_anteriorActionPerformed(evt);
            }
        });

        field_codigo.setCursor(new java.awt.Cursor(java.awt.Cursor.E_RESIZE_CURSOR));
        field_codigo.setEditable(false);
        field_codigo.setForeground(new java.awt.Color(255, 51, 102));

        botao_proximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/proximo_registro.gif"))); // NOI18N
        botao_proximo.setToolTipText("Próximo cliente");
        botao_proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_proximoActionPerformed(evt);
            }
        });

        botao_ultimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/ultimo_registro.gif"))); // NOI18N
        botao_ultimo.setToolTipText("Ir para o último cliente");
        botao_ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_ultimoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panel_botoes_caminhamentoLayout = new javax.swing.GroupLayout(panel_botoes_caminhamento);
        panel_botoes_caminhamento.setLayout(panel_botoes_caminhamentoLayout);
        panel_botoes_caminhamentoLayout.setHorizontalGroup(
            panel_botoes_caminhamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_botoes_caminhamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botao_primeiro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_anterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(field_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_proximo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_ultimo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panel_botoes_caminhamentoLayout.setVerticalGroup(
            panel_botoes_caminhamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_botoes_caminhamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_botoes_caminhamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(botao_ultimo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(botao_proximo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(botao_anterior, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(botao_primeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(field_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(58, 58, 58))
        );

        javax.swing.GroupLayout panel_clienteLayout = new javax.swing.GroupLayout(panel_cliente);
        panel_cliente.setLayout(panel_clienteLayout);
        panel_clienteLayout.setHorizontalGroup(
            panel_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_clienteLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(panel_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 233, Short.MAX_VALUE)
                .addComponent(panel_botoes_caminhamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
            .addGroup(panel_clienteLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(panel_dados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(panel_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(panel_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(61, Short.MAX_VALUE))
        );
        panel_clienteLayout.setVerticalGroup(
            panel_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_clienteLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(panel_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panel_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panel_botoes_caminhamento, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(panel_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panel_dados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panel_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panel_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        card_cliente.addTab("Clientes", panel_cliente);

        botao_alterar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/alterar_registro.gif"))); // NOI18N
        botao_alterar.setText("Alterar");
        botao_alterar.setToolTipText("Alterar cliente cadastrado");
        botao_alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_alterarActionPerformed(evt);
            }
        });

        botao_gravar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_gravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/grava_registro.gif"))); // NOI18N
        botao_gravar.setText("Gravar");
        botao_gravar.setToolTipText("Gravar novo cliente");
        botao_gravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_gravarActionPerformed(evt);
            }
        });

        botao_novo.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/novo_registro.gif"))); // NOI18N
        botao_novo.setText("Novo");
        botao_novo.setToolTipText("Novo registro");
        botao_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_novoActionPerformed(evt);
            }
        });

        botao_excluir.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/delete_registro.gif"))); // NOI18N
        botao_excluir.setText("Excluir");
        botao_excluir.setToolTipText("Excluir cliente");
        botao_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_excluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panel_botoes_crudLayout = new javax.swing.GroupLayout(panel_botoes_crud);
        panel_botoes_crud.setLayout(panel_botoes_crudLayout);
        panel_botoes_crudLayout.setHorizontalGroup(
            panel_botoes_crudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_botoes_crudLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botao_novo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_gravar, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_alterar, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botao_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        panel_botoes_crudLayout.setVerticalGroup(
            panel_botoes_crudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_botoes_crudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(botao_alterar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(botao_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(botao_gravar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(botao_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(card_cliente, javax.swing.GroupLayout.DEFAULT_SIZE, 954, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(label_titulo, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(panel_botoes_crud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(label_titulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panel_botoes_crud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(card_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-990)/2, (screenSize.height-463)/2, 990, 463);
    }// </editor-fold>//GEN-END:initComponents
    private void botao_alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_alterarActionPerformed
        try {
            if(!field_codigo.getText().equalsIgnoreCase("")){
                int op = control.alterarCliente(
                        field_codigo.getText(),
                        field_nome.getText(),
                        field_cpf.getText(),
                        field_email.getText(),
                        field_tel_celular.getText(),
                        field_tel_comercial.getText(),
                        field_tel_residencial.getText(),
                        field_end_rua.getText(),
                        field_end_bairro.getText(),
                        field_end_bairro.getText(),
                        field_end_cidade.getText());
                if(op == 1)
                    JOptionPane.showMessageDialog(null, "Alteração realizada com sucesso!");
            }
            else
                JOptionPane.showMessageDialog(null, "Primeiro selecione um cadastro!");
        } catch (SQLException erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas no banco de dados! \nNão foi possível efetuar a alteração do cadastro!");
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas para alterar o cadastro!");
        }
}//GEN-LAST:event_botao_alterarActionPerformed

    private void botao_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_novoActionPerformed
        try {
            this.limpaFields();
            control.limpaAtributosAnimal();
        } 
        catch (SQLException ex) {}
        catch (Exception ex) {}
}//GEN-LAST:event_botao_novoActionPerformed

    private void botao_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_excluirActionPerformed
        try {
            if(!field_codigo.getText().equalsIgnoreCase("")){
                int op = control.excluir(field_codigo.getText());
                this.limpaFields();
                if(op == 1)
                    JOptionPane.showMessageDialog(null, "Cadastro excluído com sucesso!");
            }
            else
                JOptionPane.showMessageDialog(null, "Primeiro selecione um cadastro!");
        } catch (Exception erro) {
                System.out.println("Erro: " + erro.getMessage());
                JOptionPane.showMessageDialog(null, "Não foi possível efetuar a exclusão do cadastro do cliente!");
        }
}//GEN-LAST:event_botao_excluirActionPerformed

    private void botao_gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_gravarActionPerformed
        try {
            if(field_codigo.getText().equalsIgnoreCase("") && field_nome.getText().equalsIgnoreCase("") )
                JOptionPane.showMessageDialog(null,"Obrigatório o preenchimento do campo: Nome do Cliente");
            else {
                if(!field_codigo.getText().equalsIgnoreCase("") && !field_nome.getText().equalsIgnoreCase("") )
                    JOptionPane.showMessageDialog(null,"Cadastro do cliente "+field_nome.getText()+" já foi realizado.");
                else {
                    if(field_codigo.getText().equalsIgnoreCase("") && !field_nome.getText().equalsIgnoreCase("") ){
                        int op = control.cadastraCliente(
                            field_nome.getText(),
                            field_cpf.getText(),
                            field_email.getText(),
                            field_tel_celular.getText(),
                            field_tel_residencial.getText(),
                            field_tel_comercial.getText(),
                            field_end_rua.getText(),
                            field_end_bairro.getText(),
                            field_end_bairro.getText(),
                            field_end_cidade.getText());
                        if(op == 1)
                            JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso!");
                    }
                }
            }                            
        } catch (SQLException erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas no banco de dados! \nNão foi possível efetuar a gravação do cadastro do cliente!");
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas para gravar o cadastro!");
        }
}//GEN-LAST:event_botao_gravarActionPerformed

    private void field_pesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_field_pesquisaActionPerformed
        try {
            this.setAtributos(control.pesquisa_digitacao(field_pesquisa.getText().length(), field_pesquisa.getText()));
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Nenhum cadastro encontrado");
        }
}//GEN-LAST:event_field_pesquisaActionPerformed

    private void botao_ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_ultimoActionPerformed
        try {
            this.setAtributos(control.ultimoCliente());
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Banco de dados vazio.");
        }
}//GEN-LAST:event_botao_ultimoActionPerformed

    private void botao_proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_proximoActionPerformed
        try {
            ArrayList<String> result;
            if(field_codigo.getText().equalsIgnoreCase("")){
                result = control.primeiroCliente();
                this.setAtributos(result);
            } else {
                result = control.proximoCliente(field_codigo.getText());
                this.setAtributos(result);
            }
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null,"Não exitem mais cadastros.");
        }
}//GEN-LAST:event_botao_proximoActionPerformed

    private void botao_anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_anteriorActionPerformed
        try {
            ArrayList<String> result;
            if(field_codigo.getText().equalsIgnoreCase("")){
                result = control.primeiroCliente();
                this.setAtributos(result);
            } else {
                result = control.anteriorCliente(field_codigo.getText());
                this.setAtributos(result);
            }
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null,"Não exitem mais cadastros.");
        }
}//GEN-LAST:event_botao_anteriorActionPerformed

    private void botao_primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_primeiroActionPerformed
        try {
            this.setAtributos(control.primeiroCliente());
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Banco de dados vazio.");
        }
}//GEN-LAST:event_botao_primeiroActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botao_alterar;
    private javax.swing.JButton botao_anterior;
    private javax.swing.JButton botao_excluir;
    private javax.swing.JButton botao_gravar;
    private javax.swing.JButton botao_novo;
    private javax.swing.JButton botao_primeiro;
    private javax.swing.JButton botao_proximo;
    private javax.swing.JButton botao_ultimo;
    private javax.swing.JTabbedPane card_cliente;
    private java.awt.TextField field_codigo;
    private javax.swing.JFormattedTextField field_cpf;
    private javax.swing.JTextField field_email;
    private javax.swing.JTextField field_end_bairro;
    private javax.swing.JFormattedTextField field_end_cep;
    private javax.swing.JTextField field_end_cidade;
    private javax.swing.JTextField field_end_rua;
    private javax.swing.JTextField field_nome;
    private javax.swing.JTextField field_pesquisa;
    private javax.swing.JFormattedTextField field_tel_celular;
    private javax.swing.JFormattedTextField field_tel_comercial;
    private javax.swing.JFormattedTextField field_tel_residencial;
    private javax.swing.JLabel label_cpf;
    private javax.swing.JLabel label_email;
    private javax.swing.JLabel label_end_bairro;
    private javax.swing.JLabel label_end_cep;
    private javax.swing.JLabel label_end_cidade;
    private javax.swing.JLabel label_end_rua;
    private javax.swing.JLabel label_nome;
    private javax.swing.JLabel label_pesquisar;
    private javax.swing.JLabel label_tel_celular;
    private javax.swing.JLabel label_tel_comercial;
    private javax.swing.JLabel label_tel_residencial;
    private javax.swing.JLabel label_titulo;
    private javax.swing.JPanel panel_botoes_caminhamento;
    private javax.swing.JPanel panel_botoes_crud;
    private javax.swing.JPanel panel_cliente;
    private javax.swing.JPanel panel_dados;
    private javax.swing.JPanel panel_endereco;
    private javax.swing.JPanel panel_pesquisar;
    private javax.swing.JPanel panel_telefone;
    // End of variables declaration//GEN-END:variables

}
